import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-22
 * Time: 9:57
 */
class Solution1 {
    public int lastStoneWeight(int[] stones) {
        //大根堆
        PriorityQueue<Integer> heap = new PriorityQueue<>((a, b) -> b-a);
        for(int x : stones){
            heap.add(x);
        }
        while(heap.size() >= 2){
            int a = heap.poll();
            int b = heap.poll();
            if(a != b){
                heap.add(a - b);//先弹出的大
            }
        }
        return heap.isEmpty() ? 0 : heap.peek();

    }
}
public class Test1 {
}
